<!--
 * @Description: 工程评估审批
 * @Author: wangwangwang
 * @Date: 2020-11-18 15:34:16
 * @LastEditors: wangwangwang
 * @LastEditTime: 2021-06-03 14:02:09
-->
<template>
  <div v-loading="loading" class="flows-content">
    <el-container>
      <el-main style="margin-bottom: 20px; padding: 0;">
        <el-container direction="vertical">
          <FlowHeader :isReadOnly="readOnly" @saveSubmit="handleSubmit(1)" @sendSubmit="handleSubmit(2)" @handleBackEnd="handleSubmit(3)" @handleCC="handleSubmit(4)" @handleAssign="handleSubmit(5)" @handleBackUp="handleSubmit(6)" @handleAssist="handleSubmit(7)" @handleNode="handleSubmit(8)" @handleNodeImage="handleSubmit(9)" @handleCollection="handleSubmit(10)" />
          <el-main class="info">
            <div>
              <el-input v-model="title" class="flow-title" :disabled="$route.query.type*1!==1" placeholder="请输入流程标题"></el-input>
            </div>
            <div class="info-top">
              <div class="left">
                <span>单据号码：{{billCode}}</span>
                <span class="text">制单日期：{{billDate}}</span>
              </div>
              <div class="right">
                <span>发起人：{{applyPerson}}</span>
                <span class="text">状态：{{taskTypeText[taskStatus*1]}}</span>
              </div>
            </div>
            <div class="form-container">
              <div class="form-title">
                <div>工程基本信息</div>
                <div style="color:rgb(255, 0, 0);">风险等级：{{projectForm.riskGrade}}<span style="margin-left:10px;">预估收益：{{projectForm.forecastEarnings}} 元</span> </div>
              </div>
              <el-form ref="projectForm" :disabled="readOnly" :model="projectForm" label-width="110px">
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="projectName">
                      <span slot="label" style="color: #ff0000">工程名称</span>
                      <el-input v-model="projectForm.projectName"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="place">
                      <span slot="label" style="color: #ff0000">地理位置</span>
                      <el-input v-model="projectForm.place"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="roadwork">
                      <span slot="label" style="color: #ff0000">合同单位</span>
                      <el-input v-model="projectForm.roadwork"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="constructionUnit">
                      <span slot="label">建设单位</span>
                      <el-input v-model="projectForm.constructionUnit"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="projectProperty">
                      <span slot="label" style="color: #ff0000">工程性质</span>
                      <el-input v-model="projectForm.projectProperty"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="operationMode" label="运作模式">
                      <el-select ref="selection1" v-model="projectForm.operationModeId" style="width:397.33px;">
                        <el-option v-for="(item, index) in operationModeList" :key="index" :label="item.itemName" :value="item.id"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="supplyCentre" label="拟供应站点">
                      <el-input v-model="projectForm.supplyCentre"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="haulDistance">
                      <span slot="label" style="color: #ff0000">运距</span>
                      <el-input v-model="projectForm.haulDistance"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="capitalSource" label="资金来源">
                      <el-select v-model="projectForm.capitalSource" style="width:397.33px;">
                        <el-option v-for="(item, index) in capitalSourceList" :key="index" :label="item.itemName" :value="item.id"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="advanceFund" label="垫资测算">
                      <el-input v-model="projectForm.advanceFund"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="continueMoney" label="承接价值">
                      <el-input v-model="projectForm.continueMoney"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="estimateNum" class="FZYdanWei">
                      <span slot="label" style="color: #ff0000">预估用砼量</span>
                      <el-input v-model="projectForm.estimateNum" type="Number">
                        <template slot="append">方</template>
                      </el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="estimatePrices" class="FZYdanWei">
                      <span slot="label" style="color: #ff0000">预估总收入</span>
                      <el-input v-model="projectForm.estimatePrices" type="Number">
                        <template slot="append">元</template>
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="estimateCost" class="FZYdanWei">
                      <span slot="label" style="color: #ff0000">预估总成本</span>
                      <el-input v-model="projectForm.estimateCost" type="Number">
                        <template slot="append">元</template>
                      </el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="施工工期" style="width: 520px">
                      <el-date-picker v-model="beginTimeFinishTime" type="datetimerange" unlink-panels range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="挂靠单位" class="FZYdanWei">
                      <el-input v-model="projectForm.attachedUnits"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="施工单位" class="FZYdanWei">
                      <el-input v-model="projectForm.contractSigningUnit"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <div class="hr"></div>
                <div class="form-title">施工单位情况</div>
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="roadworkEnrollTime">
                      <span slot="label" style="color: #ff0000">成立时间</span>
                      <el-date-picker v-model="projectForm.roadworkEnrollTime" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="roadworkEnrollFund">
                      <span slot="label" style="color: #ff0000">注册资本</span>
                      <el-input v-model="projectForm.roadworkEnrollFund" style="width: 100%"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="roadworkRatioInvestments">
                      <span slot="label">出资结构</span>
                      <el-input v-model="projectForm.roadworkRatioInvestments" style="width: 100%"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="roadworkBusinessAddress">
                      <span slot="label">经营地</span>
                      <el-input v-model="projectForm.roadworkBusinessAddress"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="roadworkDomicile">
                      <span slot="label">注册地</span>
                      <el-input v-model="projectForm.roadworkDomicile"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-form-item prop="roadworkPledgeStatus">
                    <span slot="label">抵押情况</span>
                    <el-col :span="5">
                      <el-radio v-model="projectForm.roadworkPledgeStatus" :label="0">无</el-radio>
                      <el-radio v-model="projectForm.roadworkPledgeStatus" :label="1">有</el-radio>
                    </el-col>
                    <el-col :span="19">
                      <el-input v-model="projectForm.roadworkPledge"></el-input>
                    </el-col>
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <el-form-item prop="roadworkLitigationStatus">
                      <span slot="label">涉诉情况</span>
                      <el-col :span="5">
                        <el-radio v-model="projectForm.roadworkLitigationStatus" :label="0">无</el-radio>
                        <el-radio v-model="projectForm.roadworkLitigationStatus" :label="1">有</el-radio>
                      </el-col>
                      <el-col :span="19">
                        <el-input v-model="projectForm.roadworkLitigation"></el-input>
                      </el-col>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-form-item prop="roadworkRun" label="运营情况">
                    <el-input v-model="projectForm.roadworkRun"></el-input>
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-form-item prop="roadworkHistoryCooperation" label="合作情况">
                    <span slot="label">合作情况</span>
                    <el-col :span="5">
                      <el-radio v-model="projectForm.cuLitigationStatus" :label="0">无</el-radio>
                      <el-radio v-model="projectForm.cuLitigationStatus" :label="1">有</el-radio>
                    </el-col>
                    <el-col :span="19">
                      <el-input v-model="projectForm.roadworkHistoryCooperation"></el-input>
                    </el-col>
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-form-item prop="roadworkBusinessPotential" label="经营潜力">
                    <el-input v-model="projectForm.roadworkBusinessPotential"></el-input>
                  </el-form-item>
                </el-row>
                <div class="hr"></div>
                <div class="form-title">建设单位情况</div>
                <el-row>
                  <el-col :span="12">
                    <el-form-item prop="cuEnrollTime">
                      <span slot="label" style="color: #ff0000">成立时间</span>
                      <el-date-picker v-model="projectForm.cuEnrollTime" type="datetime" placeholder="选择日期时间" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item prop="cuEnrollFund">
                      <span slot="label" style="color: #ff0000">注册资本</span>
                      <el-input v-model="projectForm.cuEnrollFund">
                        <template slot="append">万</template>
                      </el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="出资结构">
                      <el-input v-model="projectForm.cuRatioInvestments"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="经营地址">
                      <el-input v-model="projectForm.cuBusinessAddress"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12">
                    <el-form-item label="注册地址">
                      <el-input v-model="projectForm.cuDomicile"></el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-form-item prop="cuPledge" label="抵押情况">
                    <el-col :span="5">
                      <el-radio v-model="projectForm.cuPledgeStatus" :label="0">无</el-radio>
                      <el-radio v-model="projectForm.cuPledgeStatus" :label="1">有</el-radio>
                    </el-col>
                    <el-col :span="19">
                      <el-input v-model="projectForm.cuPledge" :disabled="projectForm.cuPledgeStatus===0"></el-input>
                    </el-col>
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-form-item prop="cuLitigation" label="涉诉情况">
                    <el-col :span="5">
                      <el-radio v-model="projectForm.cuLitigationStatus" :label="0">无</el-radio>
                      <el-radio v-model="projectForm.cuLitigationStatus" :label="1">有</el-radio>
                    </el-col>
                    <el-col :span="19">
                      <el-input v-model="projectForm.cuLitigation" :disabled="projectForm.cuLitigationStatus===0"></el-input>
                    </el-col>
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-form-item prop="cuBusinessPotential" label="经营潜力">
                    <el-input v-model="projectForm.cuBusinessPotential" style="width: 100%"></el-input>
                  </el-form-item>
                </el-row>
                <el-row>
                  <el-form-item prop="cuTheCityIsDevelopment" label="开发情况">
                    <el-input v-model="projectForm.cuTheCityIsDevelopment" style="width: 100%"></el-input>
                  </el-form-item>
                </el-row>
              </el-form>
              <div class="hr"></div>
              <div class="form-title">关键项梳理</div>
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="projectFormData" tooltip-effect="dark">
                <el-table-column prop="name" label="关键项" width="220"></el-table-column>
                <el-table-column label="梳理结果">
                  <template slot-scope="scope">
                    <el-input v-model="projectForm[scope.row.value]" :disabled="readOnly" style="width: 100%"></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="结果评分" width="150px">
                  <template slot-scope="scope">
                    <el-input v-model="projectForm[scope.row.score]" :disabled="readOnly" style="width:100%"></el-input>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="flows-details">
              <FlowContent ref="flowcontent" :title='title' :showSendVisible="showSendVisible" @handleCancel="handleCancel" @handleBusiness="handleBusiness" @sendCode="sendCode" @handleFinish="handleFinish" @submitData="submitDataType" @resetFlowState="resetFlowState" />
            </div>
          </el-main>
        </el-container>
      </el-main>
    </el-container>
  </div>
</template>
<script>
import FlowContent from '@/components/WorkFlow/flowContent';
import FlowHeader from '@/components/WorkFlow/flowHeader';
import { getDicType } from "@/api/common.js";
import { getDetails } from "@/api/internetSales/projectAssess.js";
import { UpdatePingGu } from "@/api/internetSales/projectClarifi.js";
import { getUserInfo } from "@/utils/auth.js";
export default {
  components: {
    FlowContent,
    FlowHeader,
  },
  data() {
    return {
      loading: false,
      taskTypeText: ['发起', '已保存', '审批中', '已完成', '撤销', '不通过'],
      taskStatus: 0,
      title: '工程评估审批',
      billCode: '',
      billDate: '',
      showSendVisible: false,
      readOnly: true,
      sendPerson: '',
      dataContent: {},
      projectForm: {},
      formData: {},
      applyPerson: '',
      projectFormData: [
        { name: "合同甲方", value: "firstParty", score: 'firstPartyScore' },
        { name: "商务价格", value: "businessPrice", score: 'businessPriceScore' },
        { name: "合同额度", value: "contractAmount", score: 'contractAmountScore' },
        { name: "甲供（卖）材料、周转材料代管约定", value: "appoint", score: 'appointScore' },
        { name: "计量", value: "measure", score: 'measureScore' },
        { name: "结算", value: "settleAccounts", score: 'settleAccountsScore' },
        { name: "发票出具", value: "invoice", score: 'invoiceScore' },
        { name: "付款办法", value: "paymentMethod", score: 'paymentMethodScore' },
        { name: "保证金", value: "earnestMoney", score: 'earnestMoneyScore' },
        { name: "资料交付条件", value: "conditions", score: 'conditionsScore' },
        { name: "供应保障责任", value: "supplyGuarantee", score: 'supplyGuaranteeScore' },
        { name: "质量及技术要求", value: "technicalRequirements", score: 'technicalRequirementsScore' },
        { name: "预期结算及支付制约条款", value: "payTeraty", score: 'payTeratyScore' },
        { name: "停工缓建约定", value: "lockoutTreaty", score: 'lockoutTreatyScore' },
        { name: "争议解决方式", value: "disputeResolution", score: 'disputeResolutionScore' },
        { name: "其他关键条款", value: "otherKeyTerms", score: 'otherKeyTermsScore' },
      ],
      beginTimeFinishTime: '',
      operationModeList: [],
      capitalSourceList: [
        { itemName: '财政预算投资', id: '1' },
        { itemName: '自筹资金投资', id: '2' },
        { itemName: '银行贷款投资', id: '3' },
        { itemName: '利用外资', id: '4' },
        { itemName: '利用有价证券', id: '5' },],
    }
  },
  methods: {
    /**
     * @Description: 
     * @param {*}statusType 1委托交底 2评估 3投标 4合同交底
     * @Author: wangwangwang
     */
    submitDataType() {
      const { query } = this.$route;
      const data = JSON.parse(query.dataContent);
      UpdatePingGu({
        engineeringId: data.engineeringManagementId,
        statusNum: 2,
        statusType: 2, 
      });
    },
    resetFlowState (type) {
      const { query } = this.$route;
      const data = JSON.parse(query.dataContent);
      UpdatePingGu({
        engineeringId: data.engineeringManagementId,
        statusNum: type===1?3:5,
        statusType: 2, 
      });
    },
    handleBusiness() {
      const { query } = this.$route;
      const data = JSON.parse(query.dataContent);
      const params = {
        process_success: {
          url: '/icps/system/sign/cloudSell/engineeringManagement/UpdatePingGu',
          data: {
            engineeringId: data.engineeringManagementId,
            statusType: 2,
            statusNum: 4,
          },
          httpMethod: 'post',
        },
        process_failure: ''
      }
      this.showSendVisible = false;
      this.$refs.flowcontent.handleToFlow(params);
    },
    handleSubmit(type) {
      const { query } = this.$route;
      if (query.type * 1 === 2 && type === 2 && query.taskType * 1 !== 2) { // 发起流程
        this.showSendVisible = true;
        return
      }
      const data = {
        dataSource: 'EngineeringEvaluation',
        dataContent: JSON.stringify({ engineeringManagementId: query.engineeringManagementId }),
      }
      this.$refs.flowcontent.saveFlows(type, data);
    },
    handleFinish() {
    },
    handleCancel() {
      this.showSendVisible = false;
    },
    /**
     * @Description: 回显业务数据
     * @Param: 
     * @Author: wangwangwang
     */
    initFlowsData(data) {
      this.formData = data;
      getDetails({ engineeringManagementId: data.engineeringManagementId }).then(res => {
        if (res.code === 1001) {
          this.projectForm = res.data;
          console.log(res.data)
          if (res.data.beginTime != null) {
            this.beginTimeFinishTime = [
              res.data.beginTime,
              res.data.finishTime,
            ];
          }
        }
      })
    },
    initFlowsData2() {
      const { query } = this.$route;
      this.formData = JSON.parse(query.dataContent);

      this.applyPerson = query.createUserName;
      this.taskStatus = query.taskStatus;
      getDetails({ engineeringManagementId: this.formData.engineeringManagementId }).then(res => {
        if (res.code === 1001) {
          this.projectForm = res.data;
          if (res.data.beginTime != null) {
            this.beginTimeFinishTime = [
              res.data.beginTime,
              res.data.finishTime,
            ];
          }
        }
      })
      this.title = query.taskName;
      this.billCode = query.receiptNumber;
      this.billDate = query.createTime;
    },
    sendCode(code) {
      this.billCode = code;
    },
  },
  mounted() {
    const { query } = this.$route;
    getDicType({ code: "operationMode" }).then((res) => {
      this.operationModeList = res.data.items;
    });
    if (query.type * 1 === 1) { // 发起流程
      this.initFlowsData(query);
      this.$refs.flowcontent.initBaseData('EngineeringEvaluation');
      this.billDate = new Date().Format('yyyy-MM-dd hh:mm:ss');
      this.applyPerson = getUserInfo().userRealName;
      return
    }
    this.initFlowsData2();
    if (query.isReadOnly*1===1) {
      this.readOnly = true;
    }
  }
}
</script>
<style lang="scss" scoped>
.flows-details {
  margin-top: 20px;
}
.info {
  padding: 0 20px;
  background: #fff;
  .info-top {
    font-size: $font_size;
    color: #000000;
    @include discen_al;
    justify-content: space-between;
    height: 50px;
    border-bottom: 1px #e1e5ed solid;
    .left {
      @include discen_al;
    }
    .text {
      margin-left: 60px;
    }
  }
}
.form-title {
  font-size: 18px;
  margin: 10px 0;
  display: flex;
  justify-content: space-between;
}
.nav_title {
  @include discen_al;
  align-items: flex-end;
  > div {
    width: 4px;
    height: 24px;
    background: $bg_color;
    margin-right: 10px;
  }
  i {
    margin-left: 5px;
  }
  color: $bg_color;
  font-size: 20px;
  font-weight: bold;
}
.form-title {
  font-size: 18px;
  margin: 10px 0;
  display: flex;
  justify-content: space-between;
}
</style>